package com.liux.rabbitmq.two;

import com.liux.rabbitmq.utils.RabbitMQUtil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 这是一个工作线程，相当于消费者
 */
public class Work01 {
    public static final String QUEUE_NAME="hello";

    public static void main(String[] args) {
        Channel channel = null;
        //接收消息回调接口
        DeliverCallback deliverCallback = (var1 ,var2) ->{
            System.out.println("消息消费成功，消息为："+new String(var2.getBody()));
        };
        //取消消息回调接口
        CancelCallback cancelCallback = (var1) ->{
            System.out.println("消息被消费者取消，信息为："+var1);
        };
        try {
            channel = RabbitMQUtil.getChannel();
            System.out.println("C2,准备接收消息===========================");
            //消息的接收
            channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }

    }
}
